//
//  HNSH_OrderDetailAddressView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/1.
//

#import "HNSH_OrderDetailAddressView.h"

@interface HNSH_OrderDetailAddressView ()

/**  */
@property (nonatomic, strong)UILabel * nameLabel;
/**  */
@property (nonatomic, strong)UIImageView * imgView;
/**  */
@property (nonatomic, strong)UILabel * addressLabel;
/**  */
@property (nonatomic, strong)UIImageView * defultImgView;

@end

@implementation HNSH_OrderDetailAddressView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

//MARK: Cycle Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.imgView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.defultImgView];
    [self addSubview:self.addressLabel];
}

- (void)addAllLayout{
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.centerY.equalTo(self.mas_centerY);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(67);
        make.height.mas_equalTo(22);
        make.top.mas_equalTo(20);
    }];
    [self.defultImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLabel.mas_right).offset(7);
        make.width.mas_equalTo(34);
        make.height.mas_equalTo(18);
        make.centerY.mas_equalTo(self.nameLabel.mas_centerY);
    }];
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(67);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(6);
        make.height.mas_equalTo(17);
    }];
}

//MARK: Setter Methods
- (void)setModel:(HNSH_OrderDetailModel *)model{
    _model = model;
    
    HNSH_AddressModel * addressModel = model.address;
    self.nameLabel.text = addressModel.contact;
    BOOL defaultAddress = addressModel.default_address;
    if (defaultAddress) {
        self.defultImgView.hidden = NO;
    } else {
        self.defultImgView.hidden = YES;
    }
    self.addressLabel.text = addressModel.address;
}

//MARK: Getter Methods
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.font = [UIFont boldSystemFontOfSize:16];
        _nameLabel.textColor = [UIColor appBlackLabelColor];
       
    }
    return _nameLabel;
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.image = [UIImage imageNamed:@"mine_order_detail_address_icon"];
    }
    return _imgView;
}

- (UIImageView *)defultImgView{
    if (!_defultImgView) {
        _defultImgView = [UIImageView new];
        _defultImgView.image = [UIImage imageNamed:@"mine_order_detail_defult_icon"];
    }
    return _defultImgView;
}

- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = [UILabel new];
        _addressLabel.font = [UIFont systemFontOfSize:12];
        _addressLabel.textColor = [UIColor appGrayLabelColor];
    }
    return _addressLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
